namespace ClassyBlog.DataAccess.Specs.Unit
{
    using System;

    using Machine.Specifications;

    [Subject(typeof(DataFileConfiguration))]
    public class when_separator_is_in_restrictied_characters
    {
        static Exception exception;

        Because of = () => exception =
            Catch.Exception(() => DataFileConfiguration.Separator = '/');

        It should_throw_exception = () =>
            exception.ShouldBeOfType<ArgumentException>();
    }

    [Subject(typeof(DataFileConfiguration))]
    public class when_separator_is_in_date_formatting_characters
    {
        static Exception exception;

        Because of = () => exception =
            Catch.Exception(() => DataFileConfiguration.Separator = 'd');

        It should_throw_exception = () =>
            exception.ShouldBeOfType<ArgumentException>();
    }

    [Subject(typeof(DataFileConfiguration))]
    public class when_separator_is_set_to_any_valid_character
    {
        static char previous;

        Establish context = () => previous = DataFileConfiguration.Separator;

        Because of = () => DataFileConfiguration.Separator = '@';

        It should_set = () => DataFileConfiguration.Separator.ShouldEqual('@');

        Cleanup on_exit = () => DataFileConfiguration.Separator = previous;
    }

    [Subject(typeof(DataFileConfiguration))]
    public class when_hidden_prefix_is_in_restrictied_characters
    {
        static Exception exception;

        Because of = () => exception =
            Catch.Exception(() => DataFileConfiguration.HiddenPrefix = ':');

        It should_throw_exception = () =>
            exception.ShouldBeOfType<ArgumentException>();
    }

    [Subject(typeof(DataFileConfiguration))]
    public class when_hidden_prefix_is_in_date_formatting_characters
    {
        static Exception exception;

        Because of = () => exception =
            Catch.Exception(() => DataFileConfiguration.HiddenPrefix = 'M');

        It should_throw_exception = () =>
            exception.ShouldBeOfType<ArgumentException>();
    }

    [Subject(typeof(DataFileConfiguration))]
    public class when_hidden_prefix_is_set_to_any_valid_character
    {
        static char previous;

        Establish context = () =>
            previous = DataFileConfiguration.HiddenPrefix;

        Because of = () => DataFileConfiguration.HiddenPrefix = '_';

        It should_set = () => DataFileConfiguration.Separator.ShouldEqual('_');

        Cleanup on_exit = () => DataFileConfiguration.HiddenPrefix = previous;
    }
}